3、刷题统计

题目 刷题统计

image-5a0d0777

思路分析

最朴素的做法 一天一天往后枚举 发现是周末就+=b 其他就+=a

看刷题数大于n的时候是第几天

#include <bits/stdc++.h>

using namespace std;

int main()

{

  long long a,b,n;cin>>a>>b>>n;

  long long cnt=1,sum=0;

  while(true){

    if(cnt%7==6 || cnt%7==0)

        sum+=b;

    else

        sum+=a;

    if(sum>=n){

       cout<<cnt;

       return 0;

    }

    cnt++;

  }

  return 0;

}

n过于大了有18位 所以这样只能过6个

借鉴之前时分秒单位换算的思路

先看一个星期能刷多少题 然后除一下得到花了几个星期 模一下得到还剩多少题 再看这多少题需要花多少天 累计一下就出来了

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

int main()

{

  LL a,b,n;cin>>a>>b>>n;

  int weekwork=a*5+b*2;  //cout<<"一周做: "<<weekwork<<endl;

  LL spendweek=n/weekwork; //cout<<"花了x周: "<<spendweek<<endl;

  LL remain=n%weekwork; //cout<<"还剩x道题: "<<remain<<endl;

  LL costdays=spendweek*7;

  int cnt=1;

  while(remain>0){

  	if(cnt%7==6 && cnt%7==0)

  		remain-=b;

  	else

  		remain-=a;

  	costdays++;

  	cnt++;

  }

  cout<<costdays;

  return 0;

}
#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

int main() {

    LL a, b, n;

    cin >> a >> b >> n;

    LL weekwork = a * 5 + b * 2;

    LL spendweek = n / weekwork;

    LL remain = n % weekwork;

    LL spendday = 0;

    if (remain == 0) { // 如果刚好在周末完成,无需额外天数

        cout << 7 * spendweek;

        return 0;

    }

    if (remain <= 5 * a) { // 若剩下的题少于5*a道,在前五天完成

        spendday = (remain + a - 1) / a; // 向上取整处理

    } else { // 若剩下的题大于5*a道,在周末完成

        spendday = 5;

        remain -= 5 * a;

        spendday += (remain + b - 1) / b; // 向上取整处理

    }

    cout << 7 * spendweek + spendday;

    return 0;

}

注意a b n也要开long long

代码实现

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

int main() {

    LL a, b, n;

    cin >> a >> b >> n;

    LL weekwork = a * 5 + b * 2;

    LL spendweek = n / weekwork;

    LL remain = n % weekwork;

    LL spendday = 0;

    if (remain == 0) { // 如果刚好在周末完成,无需额外天数

        cout << 7 * spendweek;

        return 0;

    }

    if (remain <= 5 * a) { // 若剩下的题少于5*a道,在前五天完成

        spendday = (remain + a - 1) / a; // 向上取整处理

    } else { // 若剩下的题大于5*a道,在周末完成

        spendday = 5;

        remain -= 5 * a;

        spendday += (remain + b - 1) / b; // 向上取整处理

    }

    cout << 7 * spendweek + spendday;

    return 0;

}

同类题型

视频讲解


⬅️ 2、顺子日期 🏠 00-刷题理模型 ➡️ 4、修剪灌木